<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="编号" prop="id">
        <el-input
          v-model="queryParams.id"
          placeholder="请输入编号"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="指标体系" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入指标体系"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="评价方式" prop="evaluationName">
        <el-input
          v-model="queryParams.evaluationName"
          placeholder="请输入评价方式"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--el-form-item label="备注" prop="dictType">
        <el-input
          v-model="queryParams.dictType"
          placeholder="请输入备注"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item-->
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="queryParams.startDate"
          type="date"
          placeholder="开始日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>

      <el-form-item label="">
        <el-date-picker
          v-model="queryParams.endDate"
          type="date"
          placeholder="结束日期"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" v-hasPermi="['system:record:search']">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!--el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:dict:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:dict:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:dict:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:dict:export']"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-refresh"
          size="mini"
          @click="handleRefreshCache"
          v-hasPermi="['system:dict:remove']"
        >刷新缓存</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row-->

    <el-table v-loading="loading" :data="dataList"  @sort-change="handleSortChange">
      <el-table-column type="index" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" />
      <!--      <el-table-column label="标准名称" align="center" prop="standardName" :show-overflow-tooltip="true" />-->
      <el-table-column label="指标体系" align="center" prop="projectName":show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="评价方式" align="center" prop="evaluationName":show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="标准数量" align="center" prop="standardNumber":show-overflow-tooltip="true"></el-table-column>
      <!--      <el-table-column label="总评结果" align="center" prop="accessResult":show-overflow-tooltip="true"></el-table-column>-->
      <!--      <el-table-column label="状态" align="center" prop="status">-->
      <!--        <template slot-scope="scope">-->
      <!--          <el-tag :type="getStatusTagType(scope.row.status)">{{ scope.row.status }}</el-tag>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /-->
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" :sort-orders="['descending','ascending']" sortable="custom">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
          <!--          <span>{{ new Date().toLocaleString() }}</span>-->
        </template>
      </el-table-column>

      <!--el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-search"
            @click="handleView(scope.row)"
            v-hasPermi="['system:dict:remove']"
          >查看</el-button>
        </template>
      </-el-table-column-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="pageParams.pageNum"
      :limit.sync="pageParams.pageSize"
      @pagination="getRecordList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="isAddDialogOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="标准名称" prop="dictName">
          <el-input v-model="form.dictName" placeholder="请输入标准名称" />
        </el-form-item>
        <el-form-item label="编号" prop="dictType">
          <el-input v-model="form.dictType" placeholder="请输入编号" />
        </el-form-item>
        <el-form-item label="选择数据类型" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="数据类型"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="选择评估方式" prop="status">
          <el-select
            v-model="queryParams.status"
            placeholder="评估方式"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="dict in dict.type.sys_normal_disable"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--指标得分对话框-->
    <el-dialog :title="title" :visible.sync="isScoreDialogOpen" width="500px" append-to-body>
      <el-table v-loading="loading" :data="dataList2" @selection-change="handleSelectionChange">
        <el-table-column label="指标名称" align="center" prop="standardName" />
        <el-table-column label="指标介绍" align="center" prop="introduction" :show-overflow-tooltip="true" />
        <el-table-column label="得分" align="center" prop="accessResult":show-overflow-tooltip="true"></el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import { listMenu, getMenu, delMenu, addMenu, updateMenu } from "@/api/system/menu";
import {searchRecordMethod,listRecordMethod} from '@/api/evaluate/evaluateRecord'
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import IconSelect from "@/components/IconSelect";
import {searchResultMethod} from "@/api/evaluate/evaluateResult";

export default {
  name: "result/record",
  dicts: ['sys_show_hide', 'sys_normal_disable'],
  components: { Treeselect, IconSelect },
  data() {
    return {
      total:0,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 菜单表格树数据
      menuList: [],
      // 菜单树选项
      menuOptions: [],
      dataList:[],
      dataList2:[],
      //搜索的状态下拉框
      statusOptions : [
        {
          value: '审核通过',
          label: '审核通过',
        },
        {
          value: '审核失败',
          label: '审核失败',
        },
        {
          value: '待审核',
          label: '待审核',
        },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否展开，默认全部折叠
      isExpandAll: false,
      // 新增对话框显示状态，默认为false
      isAddDialogOpen: false,
      // 修改对话框显示状态，默认为false
      isUpdateDialogOpen: false,
      // 重新渲染表格状态
      refreshTable: true,
      // 查询参数
      queryParams: {
        id:undefined,
        projectName:undefined,
        evaluationName:undefined,
        startDate:undefined,
        endDate:undefined,
        menuName: undefined,
        visible: undefined,
        pageNum:1,
        pageSize:10,
        orderByColumn: undefined,
        isAsc: undefined,
      },
      pageParams:
        {
          pageNum:1,
          pageSize:10
        },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        menuName: [
          { required: true, message: "菜单名称不能为空", trigger: "blur" }
        ],
        orderNum: [
          { required: true, message: "菜单顺序不能为空", trigger: "blur" }
        ],
        path: [
          { required: true, message: "路由地址不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getRecordList();
  },
  methods: {

    getRecordList()
    {
      this.loading=true;
      listRecordMethod(this.pageParams).then(response=>
      {
        this.dataList=response.rows;
        this.loading=false;
        this.total=response.total;
      });

    },
    searchRecordList()
    {
      this.loading=true;
      searchRecordMethod(this.queryParams).then(response=>
      {
        this.dataList=response.rows;
        this.loading=false;
      })
    },
    // 选择图标
    selected(name) {
      this.form.icon = name;
    },

    /** 获取状态 */
    getStatusTagType(status) {
      if (status === '审核通过') {
        return 'success';
      } else if (status === '审核失败') {
        return 'danger';
      } else if (status === '待审核') {
        return 'warning';
      } else {
        return 'info';
      }
    },

    /** 查询菜单列表 */
    getList() {
      this.loading = true;
      listMenu(this.queryParams).then(response => {
        this.menuList = this.handleTree(response.data, "menuId");
        this.loading = false;
      });
    },
    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.menuId,
        label: node.menuName,
        children: node.children
      };
    },
    /** 查询菜单下拉树结构 */
    getTreeselect() {
      listMenu().then(response => {
        this.menuOptions = [];
        const menu = { menuId: 0, menuName: '主类目', children: [] };
        menu.children = this.handleTree(response.data, "menuId");
        this.menuOptions.push(menu);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        menuId: undefined,
        parentId: 0,
        menuName: undefined,
        icon: undefined,
        menuType: "M",
        orderNum: undefined,
        isFrame: "1",
        isCache: "0",
        visible: "0",
        status: "0"
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.searchRecordList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      this.reset();
      this.getTreeselect();
      if (row != null && row.menuId) {
        this.form.parentId = row.menuId;
      } else {
        this.form.parentId = 0;
      }
      this.open = true;
      this.title = "添加菜单";
    },
    /** 展开/折叠操作 */
    toggleExpandAll() {
      this.refreshTable = false;
      this.isExpandAll = !this.isExpandAll;
      this.$nextTick(() => {
        this.refreshTable = true;
      });
    },
    handleView(row){

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getTreeselect();
      getMenu(row.menuId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改菜单";
      });
    },
    /** 指标得分按钮操作 */
    handleScore(row){
      this.reset();
      this.getTreeselect();
      getMenu(row.id).then(response => {
        this.form = response.data;
        this.isScoreDialogOpen = true;
        this.title = "";
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.menuId != undefined) {
            updateMenu(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addMenu(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal.confirm('是否确认删除名称为"' + row.menuName + '"的数据项？').then(function() {
        return delMenu(row.menuId);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    handleSortChange(column) {
      this.pageParams.orderByColumn = column.prop;//查询字段是表格中字段名字
      this.pageParams.isAsc = column.order;//动态取值排序顺序
      this.getRecordList();
    }
  }
};
</script>

<style scoped>

</style>
